package com.example.demo.controller;

import com.example.demo.verify.ArrayValid;
import com.example.demo.common.constant.RuleCode;
import com.example.demo.common.Result;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("/array")
@Api(tags = "10、数组传参管理")
@ApiSupport(author = "罗海林", order = 10)
@Validated
public class ArrayController {

    @PostMapping("/sendParam1")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", value = "传入参数")
    })
    @ApiOperation(value = "传入数组参数1", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 1)
    public Result sendParam1(@RequestParam String[] param) {
        Result res = new Result();
        res.ok();
        res.put("list", param);
        return res;
    }

    @PostMapping("/sendParam2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", value = "传入参数")
    })
    @ApiOperation(value = "传入数组参数2", response = Result.class)
    @ApiOperationSupport(author = "罗海林", order = 2)
    public Result sendParam2(@ArrayValid(name = "姓名数组", rule = RuleCode.phone, empty = true) @RequestParam Set<String> param) {
        Result res = new Result();
        res.ok();
        res.put("list", param);
        return res;
    }

}
